package chapter1;

import java.util.Scanner;

public class Main {
    private int count = 0;

    private int length = 0;

    private String s;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int t = sc.nextInt();

        Main main = new Main();
        main.set(s.toCharArray().length, s);
        main.getResult(0, t);
        System.out.println(main.count);
    }

    private void set(int length, String s) {
        this.length = length;
        this.s = s;
    }

    private void getResult(int index, int value) {
        //左闭右开
        if (index == length) {
            if (value == 0) {
                this.count++;
            }
            return;
        }
        for (int step = 1; step <= length - index; step++) {
            int num = getNumber(index, step);
            getResult(index + step, value + num);
            getResult(index + step, value - num);
        }
    }

    private int getNumber(int startIndex, int step) {
        if (step == 1) {
            return s.charAt(startIndex) - '0';
        } else {
            return Integer.parseInt(s.substring(startIndex, startIndex + step));
        }
    }
}
